from django.db import models

# Create your models here.
class User(models.Model):

    gender = (
        ('male', "男"),
        ('female', "女"),
    )

    name = models.CharField(max_length=128, unique=True) #用户名不可重复
    password = models.CharField(max_length=256)
    email = models.EmailField(unique=True)
    sex = models.CharField(max_length=32, choices=gender, default="男")
    c_time = models.DateTimeField(auto_now_add=True)
    has_confirmed = models.BooleanField(default=False) #这一步是为了验证用户是否验证了邮箱

    def __str__(self):
        return self.name #呈现一个实例时，显示哪个字段做为描述

    class Meta:
        ordering = ["-c_time"]
        verbose_name = "用户"  #在admin页面显示的表名
        verbose_name_plural = "用户" #这个选项指定的是模型的复数形式是什么。默认是在模型的后面加一个s

class ConfirmString(models.Model):
    code = models.CharField(max_length=256)
    user = models.OneToOneField('User', on_delete=models.CASCADE)
    c_time = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.user.name + ":   " + self.code

    class Meta:

        ordering = ["-c_time"]
        verbose_name = "确认码"
        verbose_name_plural = "确认码"
